package com.example.xutils1.adapter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.BaseAdapter;

public abstract class SuperBaseAdapter<T> extends BaseAdapter {

	private ArrayList<T> mList = new ArrayList<T>();
	protected LayoutInflater mInflater;
	protected Context mContext;

	public SuperBaseAdapter(Context ctx) {
		mInflater = LayoutInflater.from(ctx);
		mContext = ctx;
	}

	public void setData(List<T> list) {
		mList.clear();
		if (list != null) {
			mList.addAll(list);
		}
	}

	public void addData(List<T> list) {
		if (list != null) {
			mList.addAll(list);
		}
	}

	public boolean isEmpty() {
		return mList.isEmpty();
	}

	public void clear() {
		mList.clear();
	}

	public void sort(Comparator<T> c) {
		Collections.sort(mList, c);
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public T getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}